package cn.sfrog.project.biz.web.controller;

import cn.sfrog.common.core.controller.BaseController;
import cn.sfrog.common.core.domain.ApiAjaxResult;
import cn.sfrog.common.core.page.TableDataInfo;
import cn.sfrog.common.utils.SecurityUtils;
import cn.sfrog.system.domain.SysNotice;
import cn.sfrog.system.domain.vo.app.AppNoticeResultVO;
import cn.sfrog.system.service.ISysNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/api/notice")
@Api(value = "/api/notice", tags = "APP通知公告相关")
public class AppNoticeController extends BaseController {
    @Autowired
    private ISysNoticeService sysNoticeService;

    @ApiOperation(value = "获取通知公告列表")
    @GetMapping("/getNoticeList")
    public TableDataInfo<List<AppNoticeResultVO>> getNoticeList(){
        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
        startPage();
        List<AppNoticeResultVO> noticeList = sysNoticeService.selectAppNoticeList(userId);
        return getDataTable(noticeList);
    }

    @ApiOperation(value = "获取通知公告详情")
    @GetMapping("/detail/{noticeId}")
    public ApiAjaxResult<SysNotice> getNoticeDetail(@PathVariable("noticeId") Long noticeId){
       SysNotice sysNotice =  sysNoticeService.selectAppNoticeDetail(noticeId);
       return ApiAjaxResult.success(sysNotice);
    }

    @ApiOperation(value = "设置全部已读")
    @PostMapping("/allRead")
    public ApiAjaxResult allRead(){
        return ApiAjaxResult.success(sysNoticeService.allRead());
    }

}
